//
//  labelAndImageBtn.m
//  wfdyy
//
//  Created by  程 强 on 16/2/25.
//  Copyright © 2016年 demon. All rights reserved.
//

#import "labelAndImageBtn.h"

#import "JTCSM.h"

@implementation labelAndImageBtn

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame iamgeName:(NSString *)iamgeName title:(NSString *)title content:(NSString *)content  Imagesize:(CGFloat)imagesize{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.btnIamgeV = [[UIImageView alloc]initWithFrame:CGRectMake(Kspace, (frame.size.height -imagesize)/2, imagesize, imagesize)];
        self.btnIamgeV.userInteractionEnabled = NO;
        self.btnIamgeV.image = [UIImage imageNamed:iamgeName];
        [self addSubview:self.btnIamgeV];

        self.btnLabel = [UILabel initWithFrame:CGRectMake(0, 0, 0, 0) text:title font:16 textAlignment:NSTextAlignmentLeft texcolor:[UIColor blackColor] backgroundColor:nil];
        [self addSubview:self.btnLabel];
        self.btnLabel.userInteractionEnabled = NO;
        
        CGRect rect = [df labelHeightWithContent:title height:frame.size.height label:self.btnLabel];
        self.btnLabel.frame = CGRectMake(Kspace+imagesize+10, 0, rect.size.width, frame.size.height);
        
        if ([content isEqualToString:@""]) {
            CGFloat footerImagesize = imagesize;
            UIImageView *footerImageV = [[UIImageView alloc]initWithFrame:CGRectMake((frame.size.width-Kspace-footerImagesize), (frame.size.height -footerImagesize)/2, footerImagesize, footerImagesize)];
            footerImageV.image = [UIImage imageNamed:@"xiangyou1.png"];
            [self addSubview:footerImageV];
        }else{
            self.contentLabel=[UILabel initWithFrame:CGRectMake(0, 0, 0, 0) text:content font:16 textAlignment:NSTextAlignmentRight texcolor:RGBACOLOR(133, 133, 133, 1) backgroundColor:nil];
            [self addSubview:self.contentLabel];
            CGRect contentRect = [df labelHeightWithContent:content height:frame.size.height label:self.contentLabel];
            self.contentLabel.userInteractionEnabled = YES;
            self.btnIamgeV.userInteractionEnabled = YES;
            self.contentLabel.frame = CGRectMake(frame.size.width-(contentRect.size.width+10+Kspace+100), 0, contentRect.size.width+100, frame.size.height);
        }
        
        [df lineViewWithHeightofTop:frame.size.height superView:self spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
       
        
    }
    return self;
}
@end
